package servlets;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import models.User;
import dao.DaoFactory;
import dao.UserDao;

public class UserList extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	private static Logger jLog = Logger.getLogger(UserList.class);
	
	final UserDao userDao = DaoFactory.getInstance().getUserDao();

	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
				
		jLog.info("Liste User...");
		
		List<User> users = userDao.list();
		req.setAttribute("users", users);
		RequestDispatcher rd = getServletContext().getRequestDispatcher("/jsp/userlist.jsp");
		rd.forward(req, resp);
		
	}

	
	
	
	
	

}
